package com.example.fence.vo;

import com.example.fence.util.Result;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.example.fence.util.FenceStoreUtil.imeiToPointList;
import static com.example.fence.util.ResultCode.FAIL;
import static com.example.fence.util.ResultCode.SUCCESS;

@Data
@Component
/**
 * {
 *     "devicesName": [
 *         "test2",
 *         "test1"
 *     ]
 * }
 */
@AllArgsConstructor
@NoArgsConstructor
public class DeleteVo {
    // 设备imei列表
    private List<String> devicesName;

    // 校验上传要删除的IMEI是否在IMEI列表中
    public Result validateDeleteAlarm() {
        boolean found = false;  // 默认不在枚举列表中
        for (String device : devicesName) {  // 遍历设备列表
            if (!imeiToPointList.containsKey(device)) {  // 要删除的imei不在imei列表中
                return new Result(FAIL.code, false, devicesName,device+" is not in Device List!");
                }
            }
        return new Result(SUCCESS.code,true,devicesName,"success");
    }

}
